package team.xiaobaiya.gptchatrobot.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.xiaobaiya.gptchatrobot.entity.database.UserKey;
import team.xiaobaiya.gptchatrobot.mapper.UserKeyMapper;
import team.xiaobaiya.gptchatrobot.service.UserKeyService;

/**
 * @ClassName UserKeyServiceImpl
 * @Author Feng Yingnan
 * @Email fengyn1211@163.com
 * @Date 2023/4/24 15:51
 */
@Service
public class UserKeyServiceImpl implements UserKeyService {
    @Autowired
    private UserKeyMapper userKeyMapper;

    @Override
    public UserKey selectByUserKey(String userKey) {
        return userKeyMapper.selectByKey(userKey);
    }

    @Override
    public boolean decrementUserUsage(String userKey) {
        return userKeyMapper.updateUsageDecrement(userKey) > 0;
    }

    @Override
    public boolean setUserKeyLoading(String userKey) {
        return userKeyMapper.updateUserKeyLoading(userKey, true) > 0;
    }

    @Override
    public boolean setUserKeyUnloading(String userKey) {
        return userKeyMapper.updateUserKeyLoading(userKey, false) > 0;
    }
}
